<template>
    <!-- 质量检查情况 -->
    <a-spin :spinning="loading">
      <a-card>
        <title-name :title="`${$route.query.month}月质量管理信息概览`"></title-name>
        <div style="padding: 0 20px 20px;">
          <title-name title="项目质量管理得分与排名"></title-name>
          <!-- 详情列表 -->
          <div v-if="baseInfo.scoreManagerMap">
            <div v-for="(item, index) in baseInfo.scoreManagerMap" :key="index">
              <div class="branchName">{{ item[0].branchComName }}</div>
              <div>
                <Empty v-if="!item.length" description="暂无数据" />
                <a-table v-else :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns0" :dataSource="item">
                </a-table>
              </div>
            </div>
          </div>
          <Empty v-else description="暂无数据" />
          <title-name title="实测实量统计" style="margin-top: 20px;"></title-name>
          <div v-if="baseInfo.actualMeasurement">
            <Empty v-if="baseInfo.actualMeasurement.length == 0" description="暂无数据" />
            <a-table v-else :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns1" :dataSource="baseInfo.actualMeasurement"></a-table>
          </div>
          <Empty v-else description="暂无数据" />
          <title-name title="专项治理统计" style="margin-top: 20px;"></title-name>
          <div v-if="baseInfo.specialScores">
            <Empty v-if="baseInfo.specialScores.length == 0" description="暂无数据" />
            <a-table v-else :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns2" :dataSource="baseInfo.specialScores">
            </a-table>
          </div>
          <Empty v-else description="暂无数据" />
          <title-name title="质量风险评分统计" style="margin-top: 20px;"></title-name>
          <div v-if="baseInfo.riskScores">
            <Empty v-if="baseInfo.riskScores.length == 0" description="暂无数据" />
            <a-table v-else :scroll="{ x: 1500 }" :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns3" :dataSource="baseInfo.riskScores">
            </a-table>
          </div>
          <Empty v-else description="暂无数据" />
          <title-name title="质量罚款统计" style="margin-top: 20px;"></title-name>
          <div v-if="baseInfo.detailFines">
            <Empty v-if="baseInfo.detailFines.length == 0" description="暂无数据" />
            <a-table v-else :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns4" :dataSource="baseInfo.detailFines">
            </a-table>
          </div>
          <Empty v-else description="暂无数据" />
          <title-name title="质量检查与整改统计" style="margin-top: 20px;"></title-name>
          <div v-if="baseInfo.checkCounts">
            <Empty v-if="baseInfo.checkCounts.length == 0" description="暂无数据" />
            <a-table v-else :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns5" :dataSource="baseInfo.checkCounts">
            </a-table>
          </div>
          <Empty v-else description="暂无数据" />
          <title-name title="重大及以上质量风险清单" style="margin-top: 20px;"></title-name>
          <div v-if="baseInfo.riskTracks">
            <Empty v-if="baseInfo.riskTracks.length == 0" description="暂无数据" />
            <a-table v-else :rowKey="(record, index) => record.id" bordered :pagination="false" :columns="columns6" :dataSource="baseInfo.riskTracks">
            </a-table>
          </div>
          <Empty v-else description="暂无数据" />
        </div>
      </a-card>
    </a-spin>
  </template>
  
  <script>
  import { projectmanagerquery } from '@/api/quality/qualityMonth/qualityManagementInfo' // api
  import { Empty } from 'ant-design-vue' // 无数据提示
  import assetApi from '@/api/office/asset' // api
  import { columns0, columns1, columns2, columns3, columns4, columns5, columns6 } from './qualityManagementInfoColumns'
  export default {
    name: 'a' + Date.now(),
    props: {
      // 请求参数
      queryParam: {
        type: Object,
        default: () => null
      }
    },
    components: {
      Empty,
    },
    data() {
      return {
        columns0: columns0,
        columns1: columns1,
        columns2: [],
        columns3: [],
        columns4: columns4,
        columns5: columns5,
        columns6: columns6,
        loading: false, // 加载控件
        form: {}, // 编辑表单
        visible: false, // 弹窗显隐控件
        rules: {
          manageActionScore: [{ required: true, message: '请输入管理行为得分', trigger: 'change' }]
        }, // 校验规则
        formList: [{ type: 'BaseInputNumber', keyName: 'manageActionScore', label: '管理行为得分', span: 8 }], // 弹窗表单配置项
        baseInfo: {} // 详情
      }
    },
    mounted() {
      this.columns2 = this.$clone(columns2)
      this.columns3 = this.$clone(columns2).map(item => {
        if (item.dataIndex === '-1') {
          item.title = '综合得分'
          item.width = 120
        }
        if (item.dataIndex === 'branchComName') {
          item.width = 200
        }
        return item
      })
      // 初始化
      this.init()
    },
    methods: {
      /**
       * 初始化表头
       */
       getColumns() {
        this.columns2.length === 3 &&
          assetApi.typesLabel({ type: 47 }).then((res) => {
            if (res.code === 200) {
              this.columns2.splice(
                2,
                0,
                ...res.data.map((i) => ({
                  dataIndex: i.code,
                  title: i.name,
                  align: 'center',
                  customRender: (e) => e ?? '-'
                }))
              )
              this.$forceUpdate()
            }
          })
          this.columns3.length === 3 &&
          assetApi.typesLabel({ type: 51 }).then((res) => {
            if (res.code === 200) {
              this.columns3.splice(
                2,
                0,
                ...res.data.filter(item => item.code !== '999').map((i) => ({
                  dataIndex: i.code,
                  title: i.name,
                  align: 'center',
                  customRender: (e) => e ?? '-'
                }))
              )
              this.columns3.push({
                dataIndex: '999',
                title: '主要质量风险',
                align: 'center',
                width: 200,
                fixed: 'right',
                ellipsis: true,
                customRender: (e) => e ?? '-'
              })
              this.$forceUpdate()
            }
          })
      },
      /**
       * 初始化
       */
      init() {
        this.loading = true
        this.getColumns()
        // 请求检查情况
        projectmanagerquery(this.queryParam)
          .then((res) => {
            if (res.data) {
              this.baseInfo = res.data
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
    }
  }
  </script>
  